package com.dmall.play.interview.chapter09;

public class Leetcode279V3 {

    public int numSquares(int n) {
        int[] dp = new int[n + 1];
        for (int i = 0; i <= n; i++) {
            dp[i] = i;
            for (int j = 1; j <= i; j++) {
                int square = j * j;
                if (i < square) {
                    break;
                }
                dp[i] = Math.min(dp[i], dp[i - square] + 1);
            }
        }
        return dp[n];
    }

    public static void main(String[] args) {
        Leetcode279V3 leetcode279 = new Leetcode279V3();
        System.out.println(leetcode279.numSquares(16));
    }
}
